package com.inco.cloud.server1.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.inco.cloud.server1.feign.service.FeignService;
import com.inco.cloud.server1.mapper.UserDao;
import com.inco.cloud.server1.service.UserService;
//import io.seata.spring.annotation.GlobalTransactional;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {

    //注入Mapper
    @Autowired
    private UserDao userDao;

    //注入远程调用服务
    @Autowired
    private FeignService feignService;


    @Autowired
    private HttpServletRequest request;

    @Override
    //分布式事务
    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    //限流熔断
    //@SentinelResource(value = "addUser")
    public Integer addUser(String userId, String username) {
        userDao.addUser("server1-1"+userId,"server1-"+username);
        userDao.addUser("server1-"+userId,"server1-"+username);
        feignService.addUser2("userId","username");
        if (userId.equals("server1")) {
            throw new RuntimeException("异常:模拟业务异常:Storage branch exception");
        }
        return 1 ;
    }
}